//
//  ViewController.m
//  paiduibao
//
//  Created by sun qiang on 13-4-15.
//  Copyright (c) 2013年 paiduibao. All rights reserved.
//

#import "ViewController.h"
#import "BusinessViewController.h"
#import "BankIntroductionViewController.h"
@interface ViewController ()
{
    UITableView* pBankListView;
}
@end
#define kSCNavigationBarBackgroundImageTag 6183746
@implementation ViewController

- (void)viewDidLoad
{
    pBankListView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
    pBankListView.delegate = self;
    pBankListView.dataSource = self;
    [self.view addSubview:pBankListView];
    
    
    UIView* bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 85, 44)];
        
    UIButton* rightBtn= [[[UIButton alloc]initWithFrame:CGRectMake(40, 6, 45, 32)]autorelease];
    [rightBtn addTarget:self action:@selector(showBankIntroduction:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn setImage:[UIImage imageNamed: @"menubtn"] forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed: @"menubtn_f"]forState:UIControlStateHighlighted];
    [bgView addSubview:rightBtn];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:bgView]autorelease];
    [bgView release];
    
    UINavigationBar *navBar= [self.navigationController navigationBar];
    if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [navBar setBackgroundImage:[UIImage imageNamed:@"nvbar_bg"] forBarMetrics:UIBarMetricsDefault];
    }
    else
    {
        UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavigationBarBackgroundImageTag];
        if (imageView)
        {
            [imageView removeFromSuperview];
            imageView = nil;
        }
    }
    
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}
- (void)dealloc
{
    [pBankListView release];
    [super dealloc];
}
- (void)showBankIntroduction:(UIButton*) sender
{
    BankIntroductionViewController* temp = [[BankIntroductionViewController alloc]initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:temp animated:YES];
    [temp release];
}
- (void)showSubBankIntroduction:(UIButton*) sender
{
    BankIntroductionViewController* temp = [[BankIntroductionViewController alloc]initWithNibName:nil bundle:nil];
    temp.bankIntroIndex = sender.tag;
    [self.navigationController pushViewController:temp animated:YES];
    [temp release];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* retCell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"bankcell"]autorelease];
//    retCell.selectedBackgroundView = 
    retCell.textLabel.text = [NSString stringWithFormat: @"bankBusinessCell_%d",indexPath.row];
    UIButton* bankIntroBtn= [[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 45, 32)]autorelease];
    [bankIntroBtn addTarget:self action:@selector(showSubBankIntroduction:) forControlEvents:UIControlEventTouchUpInside];
    [bankIntroBtn setImage:[UIImage imageNamed: @"menubtn"] forState:UIControlStateNormal];
    [bankIntroBtn setImage:[UIImage imageNamed: @"menubtn_f"]forState:UIControlStateHighlighted];
    [retCell addSubview:bankIntroBtn];
    
    return retCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BusinessViewController* temp = [[BusinessViewController alloc]initWithNibName:nil bundle:nil];
    temp.pBankIndex = indexPath.row;
    [self.navigationController pushViewController:temp animated:YES];
    [temp release];
}
@end
